cc.Class({
    extends: cc.Component,

    properties: {

        pipeUp:cc.Node,
        pipeDown:cc.Node,

      
    },


    onLoad: function () {
        this.isPassed = false;

        //设置管道初始横坐标
        this.node.x = cc.winSize.width/ 2 + cc.myData.OUT_SCREEN;
        this.node.y += cc.myData.getRandomByRange(cc.myData.PIPE_MIN_OFFSET_Y,cc.myData.PIPE_MAX_OFFSET_Y);
        this.pipeUp.y  += cc.myData.getRandomByRange(cc.myData.PIPE_MIN_GAP,cc.myData.PIPE_MAX_GAP);
        this.schedule(this.onPipeMove.bind(this),cc.myData.MOVE_INTERVAL);

    }, 

    onPipeMove:function(){
        this.node.x -= cc.myData.PIPE_SPAWN_INTERVAL;
    },

   update:function(dt){
       var tt = cc.find("Canvas").getComponent("Game");
       if(tt.isGameover){
           this.unscheduleAllCallbacks();
       }

       var bird = cc.find("Canvas/bg/bird");
       var birdRect = bird.getBoundingBoxToWorld();
       var pipeUpRect = this.pipeUp.getBoundingBoxToWorld();
       var pipeDownRect = this.pipeDown.getBoundingBoxToWorld();
       if(cc.rectIntersectsRect(birdRect, pipeUpRect) 
       || cc.rectIntersectsRect(birdRect,pipeDownRect)){
        tt.gameover();

       }     
       if( !this.isPassed && birdRect.x > pipeUpRect.x + pipeDownRect.width / 2 ){
           this.isPassed = true;
         tt.addScore();
       }

   },



});
